#include "sRenderTarget.h"

namespace sgui
{
namespace engine
{

void sRenderTarget::draw(const math::sRectf& rect, const res::sStretch& stretch) const
{
	if (!rect.isLegal()) return;

	switch (stretch.getMode())
	{
		case res::ESM_SCALE:
		{
			draw(rect);
			break;
		}
		case res::ESM_STRETCH:
		{
			const math::sPointf pos = rect.getPosition();
			const math::sPointf size = rect.getSize();
			const math::sPointf& tex_size = getSurfaceSize();

			res::sStretchMatrix vecMatrix, texMatrix;

			stretch.getDataMatrix(vecMatrix, rect, tex_size);
			stretch.getTextureMatrix(texMatrix, tex_size);
			
			for (int j = 0; j < 3; ++j)
			{
				for (int i = 0; i < 3; ++i)
				{
					drawClip(vecMatrix.m_data[j][i],
						texMatrix.m_data[j][i]);
				}
			}

			break;
		}
	}
}

};
};